/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function Role() {
    this.javaClass = "org.workforce.core.RoleSystem";
    this.id = "";
    this.name = "";
    this.description = "";
}
function mainRole() {
    var body = document.getElementById("_body");
    body.innerHTML = requestPage("RoleSystem.main.jsp");
}
function addRole() {
    var role = new Role();
    role.name = document.getElementById("roleName").value;
    role.description = document.getElementById("roleDescription").value;
    var chk = serviceLocator.saveRole(role);
    if( chk == "true" ) {
        alert("Add Role Complete.");
    } else {
        alert("Cann't add Role!");
    }
}
function saveRole() {
    loading();
    var role = new Role();
    role.id = document.getElementById("role_pre_id").value;
    role.name = document.getElementById("role_pre_name").value;
    role.description = document.getElementById("role_pre_description").value;
    var chk = serviceLocator.updateRole(role);
    if( chk == "true" ) {
        alert("Update Role Complete.");
    } else {
        alert("Cann't Update Role!");
    }
    unloading();
}
function searchRole() {
    loading();
    var role = new Role();
    role.name = document.getElementById("roleName").value;
    var pages = serviceLocator.pageSearchCritiriaRole(role);
    var ls = serviceLocator.searchCritiriaRole(role, 0);
    setTableHeader("roleTable", ["&nbsp;", "&nbsp;", "id",
        "Name", "description"], pages.count, ""+pages.iterator, "searchRoleN");
    loadTable("id,name,description", ls, "roleTable","delRole","edtRole");
    unloading();
}
function searchRoleN(offset) {
    loading();
    var role = new Role();
    role.name = document.getElementById("roleName").value;
    var pages = serviceLocator.pageSearchCritiriaRole(role);
    var ls = serviceLocator.searchCritiriaRole(role, offset);
    setTableHeader("roleTable", ["&nbsp;", "&nbsp;", "id",
        "Name", "description"], pages.count, ""+pages.iterator, "searchRoleN");
    loadTable("id,name,description", ls, "roleTable","delRole","edtRole");
    unloading();
}
function delRole(id) {
    var sysConfirm = new SysConfirm();
    sysConfirm.message = "You do want delete id["+id+"]";
    sysConfirm.callOK = "role_confirm_delete_ok('"+id+"')";
    sysConfirm.confirm();
}
function role_confirm_delete_ok(id) {
    var role = new Role();
    role.id = id;
    serviceLocator.removeRole(role);
    searchRole();
}
function edtRole(id) {
    loading();
    var role = new Role();
    role.id = id;
    var roleEdit = serviceLocator.findRoleSystem(role);
    actionForward('_body','RoleSystem.form.jsp');
    document.getElementById("role_pre_id").value = roleEdit.id;
    document.getElementById("role_pre_name").value = roleEdit.name;
    document.getElementById("role_pre_description").value = roleEdit.description;
    document.getElementById("role_pre_save").setAttribute("onclick", "saveRole()");
    unloading();
}
function roleClear() {
    document.getElementById("roleName").value = "";
}
